<template>
  <div ref="goodkindRef" class="pie_chart"></div>
</template>

<script setup lang="ts">
import { ref } from "@vue/reactivity";
import { onMounted } from "@vue/runtime-core";
import * as echarts from "echarts";
const goodkindRef = ref<HTMLDivElement>();
onMounted(() => {
  var myChart = echarts.init(goodkindRef.value as HTMLDivElement);
  const option = {
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "5%",
      left: "center",
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["40%", "70%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2,
        },
        label: {
          show: false,
          position: "center",
        },
        emphasis: {
          label: {
            show: true,
            fontSize: "18",
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: [
          { value: 1048, name: "家具" },
          { value: 735, name: "日常用品" },
          { value: 580, name: "食品" },
          { value: 484, name: "电器" },
          { value: 300, name: "衣服" },
        ],
      },
    ],
  };
  // 绘制图表
  myChart.setOption(option);
  //监听窗口更改大小
  window.addEventListener("resize", () => {
    myChart.resize();
  });
});
</script>

<style lang="scss" scoped>
.pie_chart {
  width: 100%;
  height: 100%;
}
</style>